package com.cskaoyan.controller.system;

import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.po.MarketStorage;
import com.cskaoyan.service.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Auther: Yang Yi-zhou
 * @Date: 2022/9/7 13:50
 * @Description:
 */
@RestController
@RequestMapping("admin/storage")
public class StorageController {

    @Autowired
    StorageService storageService;

    @RequestMapping("list")
    public BaseRespVo listStorage(Integer page, Integer limit, String sort, String order) {
        CommonData<MarketStorage> data = storageService.listStorage(page, limit, sort, order);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("update")
    public BaseRespVo updateStorage(@RequestBody MarketStorage marketStorage) {
        MarketStorage newMarketStorage = storageService.updateStorage(marketStorage);
        return BaseRespVo.ok(newMarketStorage);
    }

    @RequestMapping("delete")
    public BaseRespVo deleteStorage(@RequestBody MarketStorage marketStorage) {
        return storageService.deleteStorage(marketStorage) ? BaseRespVo.ok() : BaseRespVo.invalidData("删除失败");
    }


}
